package com.example.wrongquestioncollection;

import android.support.test.filters.SmallTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.not;

@RunWith(AndroidJUnit4.class)
@SmallTest
public class WrongQuestionListActivityTest {

    @Rule
    public ActivityTestRule<WrongQuestionListActivity> mTestRule = new ActivityTestRule<>(WrongQuestionListActivity.class);

    @Test
    public void helloWorld_DoNothing() {
        onView(withText("Hello World!")).check(matches(isDisplayed()));
    }

    @Test
    public void showToast_ClickAddNewEditWrongQuestionButton() {
        onView(withId(R.id.add_new_wrong_question_floating_action_button))
                .check(matches(isDisplayed()))
                .perform(click());

        onView(withText("Add New Wrong Question"))
                .inRoot(withDecorView(not(mTestRule.getActivity().getWindow().getDecorView())))
                .check(matches(isDisplayed()));
    }
}